package com.jahe.learn.netty4.zerocopy;


import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.Socket;

/**
 * 老式 io 机制会使文件
 * @author: jahe.lai
 * @create: 2019-12-25 20:00
 */
public class OldFileClient {

    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("127.0.0.1", 8899);
        String filename = "D:/softs/ideaIU-2019.2.4.win.zip";
        InputStream inputStream = new FileInputStream(filename);
        DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());

        long readCount = 0;
        long total = 0;
        byte[] buffer = new byte[4096];

        long st = System.currentTimeMillis();
        while ((readCount = inputStream.read(buffer)) >= 0) {
            total += readCount;
            outputStream.write(buffer);
        }
        System.out.println("发送总字节数：" + total + ", 耗时(ms)：" + (System.currentTimeMillis() - st));
        outputStream.close();
        inputStream.close();
        socket.close();
    }
}
